package asn.match.dao;

import java.util.List;

import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import asn.match.model.CommentLike;

@Repository("comment_like")
@PersistenceContext(type = PersistenceContextType.EXTENDED)
@Transactional
public class CommentLikeDaoImpl implements CommentLikeDAO {

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void addCommentLike(CommentLike commentLike) {
		this.sessionFactory.getCurrentSession().save(commentLike);
	}

	@Override
	public void updateCommentLike(CommentLike commentLike) {
		this.sessionFactory.getCurrentSession().saveOrUpdate(commentLike);
	}

	@Override
	public void deleteCommentLike(CommentLike commentLike) {
		this.sessionFactory.getCurrentSession().delete(commentLike);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CommentLike> findAllCommentLikes() {
		return (List<CommentLike>) this.sessionFactory.getCurrentSession().createQuery("from CommentLike comment_like").list();
	}

	@Override
	public CommentLike findCommentLikeById(Integer commentLikeId) {
		return (CommentLike) this.sessionFactory.getCurrentSession().get(CommentLike.class, commentLikeId);
	}
	
}
